﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ingebet.Model.Domain;
using Ingebet.Repository.Contract;
using NHibernate;
using NHibernate.Criterion;

namespace Ingebet
{
    public class RencontreRepository : Repository<Rencontre , int> , IRencontreRepository
    {
        public IList<Rencontre> GetRencontreSansResult()
        {
            ISession s = HelperSessionFactory.GetCurrentSession();
            var result = s.CreateCriteria(typeof(Rencontre))
                    .Add(Restrictions.Eq("Score" , ""))
                    .List<Rencontre>();
            return result;
        }

        public IList<Rencontre> GetRencontreAvecResult()
        {
            ISession s = HelperSessionFactory.GetCurrentSession();
            var result = s.CreateCriteria(typeof(Rencontre))
                    .Add(Restrictions.Not(Restrictions.Eq("Score" , "")))
                    .List<Rencontre>();
            return result;
        }

        //public void InsertRencontre(VueMatch match)
        //{
        //    ISession s = HelperSessionFactory.GetCurrentSession();
        //    ITransaction tran = s.BeginTransaction();
        //    try
        //    {
        //        IQuery query = s.GetNamedQuery("InsertRencontre");
        //        query.SetInt32("Sport", match.SportMatch.Id);
        //        query.SetString("Compet", match.Competition);
        //        query.SetString("Equ1", match.Equipe1);
        //        query.SetString("Equ2", match.Equipe2);
        //        query.SetDateTime("Date", match.DateMatch);
        //        query.SetDouble("Gain", match.CoteMatch.CoteGain);
        //        query.SetDouble("Egal", match.CoteMatch.CoteEgalite);
        //        query.SetDouble("Perte", match.CoteMatch.CotePerte);

        //        query.UniqueResult();
        //    }
        //    catch (Exception)
        //    {
        //        tran.Rollback();
        //    }
        //}

        //public IList<Rencontre> GetRencontreBySport(string sport)
        //{
        //    ISession s = HelperSessionFactory.GetCurrentSession();
        //    var result = s.CreateCriteria(typeof(Rencontre))
        //            .Add(Restrictions.Eq("SportMatch" , sport))
        //            .List<Rencontre>();
        //    return result;
        //}
    }
}